<template>
  <div class='wrapper'>
    <div style="margin: 20px;"></div>
    <el-form :label-position="labelPosition" label-width="80px" :model="formLabelAlign">
      <el-form-item label="手机号：">
        <el-input v-model="formLabelAlign.name"></el-input>
      </el-form-item>
      <el-form-item label="密码：">
        <el-input v-model="formLabelAlign.pass"></el-input>
      </el-form-item>
      <el-form-item label="管理员：">
        <el-select v-model="formLabelAlign.region" placeholder="请选择活动区域">
          <el-option label="普通管理员" value="1"></el-option>
          <el-option label="高级管理员" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-button type="primary" @click="change">立即修改</el-button>
      <el-button @click="off">取消</el-button>
    </el-form>
  </div>
</template>

<script>
import Axios from "axios";
export default {
  data() {
    return {
      labelPosition: "right",
      formLabelAlign: {
        name: "",
        region: "",
        pass: ""
      }
    };
  },
  mounted() {
    this.getadmin();
  },
  methods: {
    getadmin() {
      const _id = this.$route.params._id;
      Axios.get("/admin/adminone", { params: { _id } }).then(res => {
     
        this.formLabelAlign.name = res.data[0].userName;
        this.formLabelAlign.pass = res.data[0].passWord;
        this.formLabelAlign.region = res.data[0].loginState;
      });
    },
    change() {
        const _id = this.$route.params._id;
        Axios.post('admin/changeadmin',{
            _id,
            userName:this.formLabelAlign.name,
            passWord:this.formLabelAlign.pass,
            loginState:this.formLabelAlign.region,
            phone:this.formLabelAlign.name
        }).then(res=>{
            if(res.data){
                alert('修改成功!');
                this.$router.push('/admin')
            }
            
        })
    },
    off(){
        this.$router.push('/admin')
    }
  }
};
</script>

<style scoped>
.wrapper{
  height:640px;
}
</style>